package dgut.party.business.entity.org;

import com.fasterxml.jackson.annotation.JsonIgnore;
import dgut.party.business.entity.base.BaseEntity;
import dgut.party.business.entity.user.NormalUser;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.util.List;

@Getter
@Setter
@Entity
@SuperBuilder
@NoArgsConstructor
public class Organization extends BaseEntity {

  private static final long serialVersionUID = -5518095987444860322L;

  private String name;

  private String description;

  @ManyToOne(cascade = CascadeType.REFRESH)
  private NormalUser leader;

  @JsonIgnore
  @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  private List<NormalUser> members;

  // ---------------自身一对多 多对一 ------------
  @JsonIgnore
  @ManyToOne(cascade = CascadeType.ALL)
  private Organization supOrg;

  @JsonIgnore
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "supOrg", cascade = CascadeType.ALL)
  private List<Organization> subOrgs;

  // ---------------------------
}
